package com.syq;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.syq.pojo.DtsUser;
import com.syq.service.DtsOrderService;
import com.syq.service.DtsUserService;
import com.syq.vo.DayStatis;
import com.syq.vo.OrderAmtsVo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName: testDayData
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/22 20:04
 */

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( locations = {"classpath:spring/*"})
public class testDayData {
    @Autowired
    private DtsUserService dtsUserService;

    @Autowired
    private DtsOrderService dtsOrderService;

    @Test
    public void dayData() {
        List<DayStatis> userOrderCntVoList = dtsUserService.findUserOrderCntVo();

        List<DayStatis> dayStatisList = dtsOrderService.findDayStatis();

        OrderAmtsVo orderAmtsVo = new OrderAmtsVo();

        orderAmtsVo.setDayData(dayStatisList.stream()
                .map(DayStatis::getDayStr)
                .collect(Collectors.toList())
                .toArray(new String[dayStatisList.size()]));


        Integer[] orderCnt = dayStatisList.stream()
                .map(DayStatis::getCnts)
                .collect(Collectors.toList())
                .toArray(new Integer[dayStatisList.size()]);
        orderAmtsVo.setOrderCntData(orderCnt);

        orderAmtsVo.setOrderAmtData(dayStatisList.stream()
                .map(DayStatis::getAmts)
                .collect(Collectors.toList())
                .toArray(new BigDecimal[dayStatisList.size()])
        );

        String[] dayData = userOrderCntVoList.stream()
                .map(DayStatis::getDayStr)
                .collect(Collectors.toList())
                .toArray(new String[userOrderCntVoList.size()]);


        Integer[] arr=new Integer[dayData.length];
        for (int i = 0; i < dayData.length; i++) {
            int dayCnt=0;
            String dayStr=dayData[i];
            for (DayStatis dayStatis : dayStatisList) {
                if (dayStr.equals(dayStatis.getDayStr())){
                    dayCnt=dayStatis.getCnts();
                    break;
                }
            }
            arr[i]=dayCnt;
            System.out.println(arr[i]);
        }
        System.out.println(arr.length);
    }

    @Test
    public void test1(){
        dtsOrderService.findById(85);
    }
}
